var getadmingrid, addsub;
var type = null;
var addadmin, editadmin, resetpwd, deleteadmin;
var phonetset = true;

var getmallmingrid, modaladd;
var mallteltest = true;
var malltype = null;
var current, editmall, deletemall, resetpwd1, device, showtab, malltab2, getphone;
var logout, init, unloadhtml;
var showProv, showCity, showCountry;

var getsearchmingrid, updategrid;
var getordermingrid, getemployeemingrid, user, editOrder;
var searchOrderInfor, end_time, start_time, start_time_data, end_time_data;
var orderstatusdata = [{
    name: 'DONE',
    display: '完成'
}, {
    name: 'CANCELED',
    display: '取消'
}, {
    name: 'UNCONFIRMED',
    display: '未确认'
}, {
    name: 'ORDERED',
    display: '已下单'
}, {
    name: 'PRODUCING',
    display: '生产中'
}, {
    name: 'TRANSPORTING',
    display: '运输中'
}, {
    name: 'DISPATCHING',
    display: '配送中'
}, {
    name: 'VERIFY_FAILED',
    display: '鉴伪失败'
}];
angular.module('super', ['ng'])
    .controller('superCtrl', ['$scope',
        function ($scope) {
            getadmingrid = function () {
                var grid = $("#maingrid").ligerGrid({
                    url: commonobj.ip + 'admin/list',
                    parms: [
                        {name: 'keyword', value: ''}
                    ],
                    method: "get",
                    root: 'list',
                    record: 'total',
                    pageParmName: 'start',
                    pagesizeParmName: 'limit',
                    width: '98%',
                    height: '98%',
                    pageSize: 10,
                    pageSizeOptions: [10, 20, 30, 50],
                    rownumbers: true,
                    columns: [
                        {display: '账号', name: 'account', align: 'left'},
                        {display: '电话', name: 'phone', align: 'left'},
                        {display: '角色', name: 'role', align: 'left'},
                        {
                            display: '创建时间', name: 'create_time', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == 0) {
                                    return "无";
                                } else {
                                    return commonobj.timeservice(value);
                                }
                            }
                        },
                        {
                            display: '最后登录时间', name: 'last_login_time', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == 0) {
                                    return "无";
                                } else {
                                    return commonobj.timeservice(value);
                                }
                            }
                        },
                        {
                            display: '操作',
                            render: function (rowdata, rowindex, value) {
                                var str = JSON.stringify(rowdata);
                                var html = '';
                                html +=
                                    "<a class='text-primary operate_text' onclick='editadmin.show(" + str + ")'>编辑</a>&nbsp;&nbsp;" +
                                    "<a class='text-primary operate_text' onclick='resetpwd.show(" + str + ")'>重置密码</a>&nbsp;&nbsp;" +
                                    "<a class='text-primary operate_text' onclick='deleteadmin.showModel( " + str + ")'>删除</a>";
                                return html;
                            }
                        }
                    ]
                });
                $("#pageloading").hide();
                grid.bind('Success', function (data) {
                    if (data.list.length == 0) {
                        $("#zwsj").show();
                    } else {
                        $("#zwsj").hide();
                    }
                });
                grid.bind('Error', function (data) {
                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {

                    }

                });

            };
            //add
            type = null;
            addadmin = {
                showmoadal: function () {
                    type = "add";
                    $('#addadminmodal').show();
                    $('#addadminmodal .title').html('新建admin用户');
                    $("#nametext").val("");
                    $('.redtip1').css('display', 'none');
                    $('.pwd').show();
                    $("#pwdtext").val("");
                    $('.redtip2').css('display', 'none');
                    $("#teltext").val("");
                    $('.redtip3').css('display', 'none');
                },
                cancel: function () {
                    $('#addadminmodal').hide();
                }
            };
            $("#nametext").blur(function () {
                $("#nametext").val() == '' ? $('.redtip1').css('display', 'inline') : $('.redtip1').css('display', 'none');
            });
            $("#pwdtext").blur(function () {
                $("#pwdtext").val() == '' ? $('.redtip2').css('display', 'inline') : $('.redtip2').css('display', 'none');
            });
            phonetset = true;
            $("#teltext").blur(function () {
                if ($("#teltext").val() != "") {
                    var phone = document.getElementById('teltext').value;
                    phonetset = (/^1[34578]\d{9}$/.test(phone));
                    if (!(/^1[34578]\d{9}$/.test(phone))) {
                        $('.redtip3').css('display', 'inline');
                    } else {
                        $('.redtip3').css('display', 'none');
                    }
                }
            });
            addsub = function () {
                $("#nametext").val() == '' ? $('.redtip1').css('display', 'inline') : $('.redtip1').css('display', 'none');
                $("#pwdtext").val() == '' ? $('.redtip2').css('display', 'inline') : $('.redtip2').css('display', 'none');
                if ($("#teltext").val() != "") {
                    var phone = document.getElementById('teltext').value;
                    phonetset = (/^1[34578]\d{9}$/.test(phone));
                    if (!(/^1[34578]\d{9}$/.test(phone))) {
                        $('.redtip3').css('display', 'inline');
                    } else {
                        $('.redtip3').css('display', 'none');
                    }
                }
                if (type == "add") {
                    if ($("#nametext").val() !== "" && $("#pwdtext").val() !== '' && (phonetset || $("#teltext").val() == "")) {
                        var param = {
                            "account": $("#nametext").val(),
                            "pwd": $("#pwdtext").val(),
                            "phone": $("#teltext").val(),
                            "role": $("input[name='auth']:checked").val()
                        };
                        if ($("#nametext").val() !== "" && $("#pwdtext").val() !== '' && (phonetset || $("#teltext").val() == "")) {
                            var param = {
                                "account": $("#nametext").val(),
                                "pwd": $("#pwdtext").val(),
                                "phone": $("#teltext").val(),
                                "role": $("input[name='auth']:checked").val()
                            };
                            $.ajax({
                                type: "post",
                                url: commonobj.ip + "admin/create",
                                dataType: "json",
                                contentType: "application/json",
                                data: JSON.stringify(param),
                                success: function (data) {
                                    if (data.msg == "success") {
                                        $('#addadminmodal').hide();
                                        $('#modal').show();
                                        $('#content').html("新增成功");
                                        getadmingrid();
                                    }
                                },
                                error: function (data) {
                                    $('#addadminmodal').hide();
                                    $('#modal').show();
                                    $('#content').html(data.responseJSON.msg);
                                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                        commonobj.sessionExpired();
                                    }


                                }
                            });
                        }
                    }
                } else if (type == "edit") {
                    if (phonetset || $("#teltext").val() == "") {
                        var param = {
                            "id": editadmin.data.id,
                            "phone": $("#teltext").val()
                        };
                        $.ajax({
                            type: "post",
                            url: commonobj.ip + "admin/update",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify(param),
                            success: function (data) {
                                if (data.msg == "success") {
                                    $('#addadminmodal').hide();
                                    $('#modal').show();
                                    $('#content').html("编辑成功");
                                    getadmingrid();
                                }
                            },
                            error: function (data) {
                                $('#addadminmodal').hide();
                                $('#modal').show();
                                $('#content').html(data.responseJSON.msg);
                                if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                    commonobj.sessionExpired();
                                }


                            }
                        });
                    }
                }
            };
//edit
            editadmin = {
                data: null,
                show: function (obj) {
                    editadmin.data = obj;
                    type = "edit";
                    $('#addadminmodal').show();
                    $('#addadminmodal .title').html('编辑admin用户');
                    $('.account').hide();
                    $('.redtip1').css('display', 'none');
                    $('.pwd').hide();
                    $('.redtip2').css('display', 'none');
                    $("#teltext").val(obj.phone);
                    $('.redtip3').css('display', 'none');
                    $('.auth').hide();
                }
            };
//reset
            $("#pwdreset").blur(function () {
                $("#pwdreset").val() == '' ? $('.redtip21').css('display', 'inline') : $('.redtip21').css('display', 'none');
            });
            resetpwd = {
                resetid: {},
                show: function (obj) {
                    resetid = obj;
                    $('#resetpwd').show();
                    $('#pwdreset').val('');
                    $('.redtip21').css('display', 'none');
                },
                ok: function () {
                    if ($('#pwdreset').val() !== '') {
                        var param = {
                            id: resetid.id,
                            reset_pwd: $('#pwdreset').val()
                        };
                        $.ajax({
                            type: "post",
                            url: commonobj.ip + "admin/reset",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify(param),
                            success: function (data) {
                                if (data.msg == "success") {
                                    $('#resetpwd').hide();
                                    $('#modal').show();
                                    $('#content').html("重置成功");
                                }
                            },
                            error: function (data) {
                                $('#resetpwd').hide();
                                $('#modal').show();
                                $('#content').html(data.responseJSON.msg);
                                if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                    commonobj.sessionExpired();
                                }


                            }
                        });
                    } else {
                        $('.redtip21').css('display', 'inline');
                    }
                },
                cancel: function () {
                    $('#resetpwd').hide();
                }
            };
//delete
            deleteadmin = {
                data: null,
                showModel: function (str) {
                    deleteadmin.data = str;
                    $('#modald').show();
                    $('#contentd').html('确定要删除这条数据？')
                },
                ok: function () {
                    $.get(commonobj.ip + "admin/delete/" + deleteadmin.data.id).success(function (data) {
                        if (data.code == "0") {
                            $('#modald').hide();
                            $('#modal').show();
                            $('#content').html("删除成功");
                            getadmingrid();
                        }
                    }).error(function (data) {
                        $('#modald').hide();
                        $('#modal').show();
                        $('#content').html(data.responseJSON.msg);
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }


                    });
                },
                cancel: function () {
                    $('#modald').hide();
                }
            };

//mall
            getmallmingrid = function () {
                var grid = $("#maingrid1").ligerGrid({
                    url: commonobj.ip + 'mall/list',
                    method: "get",
                    parms: [
                        {name: 'keyword', value: ''}
                    ],
                    root: 'list',
                    record: 'total',
                    pageParmName: 'start',
                    pagesizeParmName: 'limit',
                    width: '98%',
                    height: '98%',
                    pageSize: 10,
                    pageSizeOptions: [10, 20, 30, 50],
                    rownumbers: true,
                    columns: [
                        {display: '门店名称', name: 'name', align: 'left'},
                        {display: '账号', name: 'account', align: 'left'},
                        {display: '电话', name: 'phone', align: 'left'},
                        {display: '省', name: 'province', align: 'left'},
                        {display: '市', name: 'city', align: 'left'},
                        {display: '区', name: 'district', align: 'left'},
                        {display: '乡镇', name: 'town', align: 'left'},
                        {display: '村名', name: 'village', align: 'left'},
                        {display: '街道', name: 'street', align: 'left'},
                        {display: '详细地址', name: 'address', align: 'left'},
                        {display: '发货地址', name: 'send_address', align: 'left'},
                        {
                            display: '操作', width: "20%",
                            render: function (rowdata, rowindex, value) {
                                var str = JSON.stringify(rowdata);
                                var html = '';
                                html +=
                                    "<a class='text-primary operate_text' onclick='malltab2.show(" + str + ")'>详情</a>&nbsp;&nbsp;" +
                                    "<a class='text-primary operate_text' onclick='editmall.show(" + str + ")'>编辑</a>&nbsp;&nbsp;" +
                                    "<a class='text-primary operate_text' onclick='resetpwd1.show(" + str + ")'>重置密码</a>&nbsp;&nbsp;" +
                                    "<a class='text-primary operate_text' onclick='deletemall.showModel( " + str + ")'>删除</a>&nbsp;&nbsp;";
                                return html;
                            }
                        }
                    ]
                });
                grid.bind('Success', function (data) {
                    if (data.list.length == 0) {
                        $("#zwsj1").show();
                    } else {
                        $("#zwsj1").hide();
                    }
                });
                grid.bind('Error', function (data) {
                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                        commonobj.sessionExpired();
                    }

                });

            };
//add
            mallteltest = true;
            malltype = null;
            modaladd = {
                showmodal: function () {
                    malltype = "add";
                    $('#modaladd').show();
                    $('#modaladd .title').html('新建经销商');
                    $("#mallname").val('');
                    $("#malltel").val('');
                    $('.redtip2').css('display', 'none');
                    $(".acctmall").show();
                    $("#mallact").val('');
                    $('.redtip3').css('display', 'none');
                    $('.pwdmall').show();
                    $("#mallpwd").val('');
                    $('.redtip4').css('display', 'none');
                    $("#prov").val('');
                    $("#city").val('');
                    $("#country").val('');
                    $("#malltown").val('');
                    $("#mallvillage").val('');
                    $("#mallstreet").val('');
                    $("#malladdr").val('');
                    $("#sendaddr").val('');
                    $('#devices').val(1);
                    showProv();
                },
                cancel: function () {
                    $('#modaladd').hide();
                },
                ok: function () {
                    if ($("#malltel").val() != "") {
                        var phone = document.getElementById('malltel').value;
                        mallteltest = (/^1[34578]\d{9}$/.test(phone));
                        if (!(/^1[34578]\d{9}$/.test(phone))) {
                            $('.redtip2').css('display', 'inline');
                        } else {
                            $('.redtip2').css('display', 'none');
                        }
                    }
                    $("#mallact").val() == '' ? $('.redtip3').css('display', 'inline') : $('.redtip3').css('display', 'none');
                    $("#mallpwd").val() == '' ? $('.redtip4').css('display', 'inline') : $('.redtip4').css('display', 'none');
                    if (malltype == "add") {
                        if ($("#mallact").val() !== '' && $("#mallpwd").val() !== '' && (mallteltest || $("#malltel").val() == "")) {
                            var param = {
                                "name": $("#mallname").val(),
                                "phone": $("#malltel").val(),
                                "account": $("#mallact").val(),
                                "pwd": $("#mallpwd").val(),
                                "province": "",
                                "city": "",
                                "district": "",
                                "town": $("#malltown").val(),
                                "village": $("#mallvillage").val(),
                                "street": $("#mallstreet").val(),
                                "address": $("#malladdr").val(),
                                "send_address": $("#sendaddr").val(),
                                "device_number_limit": Number($("#devices").val())
                            };
                            if ($("#prov").val() == "") {
                                param.province = "";
                            } else {
                                param.province = $("#prov").find("option:selected").text();
                            }
                            if ($("#city").val() == "") {
                                param.city = "";
                            } else {
                                param.city = $("#city").find("option:selected").text();
                            }
                            if ($("#country").val() == "") {
                                param.district = "";
                            } else {
                                param.district = $("#country").find("option:selected").text();
                            }
                            $.ajax({
                                type: "post",
                                url: commonobj.ip + "mall/new",
                                dataType: "json",
                                contentType: "application/json",
                                data: JSON.stringify(param),
                                success: function (data) {
                                    if (data.msg == "success") {
                                        $('#modaladd').hide();
                                        $('#modal').show();
                                        $('#content').html("新增成功");
                                        getmallmingrid();
                                    }
                                },
                                error: function (data) {
                                    $('#modaladd').hide();
                                    $('#modal').show();
                                    $('#content').html(data.responseJSON.msg);
                                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                        commonobj.sessionExpired();
                                    }


                                }
                            });
                        }
                    } else if (malltype == "edit") {
                        if (mallteltest || $("#malltel").val() == "") {
                            var param = {
                                "id": editmall.data.id,
                                "name": $("#mallname").val(),
                                "phone": $("#malltel").val(),
                                "province": "",
                                "city": "",
                                "district": "",
                                "town": $("#malltown").val(),
                                "village": $("#mallvillage").val(),
                                "street": $("#mallstreet").val(),
                                "address": $("#malladdr").val(),
                                "send_address": $("#sendaddr").val(),
                                "device_number_limit": Number($("#devices").val())
                            };
                            if ($("#prov").val() == "") {
                                param.province = "";
                            } else {
                                param.province = $("#prov").find("option:selected").text();
                            }
                            if ($("#city").val() == "") {
                                param.city = "";
                            } else {
                                param.city = $("#city").find("option:selected").text();
                            }
                            if ($("#country").val() == "") {
                                param.district = "";
                            } else {
                                param.district = $("#country").find("option:selected").text();
                            }
                            $.ajax({
                                type: "post",
                                url: commonobj.ip + "mall/update",
                                dataType: "json",
                                contentType: "application/json",
                                data: JSON.stringify(param),
                                success: function (data) {
                                    if (data.msg == "success") {
                                        $('#modaladd').hide();
                                        $('#modal').show();
                                        $('#content').html("编辑成功");
                                        getmallmingrid();
                                    }
                                },
                                error: function (data) {
                                    $('#modaladd').hide();
                                    $('#modal').show();
                                    $('#content').html(data.responseJSON.msg);
                                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                        commonobj.sessionExpired();
                                    }


                                }
                            });
                        }
                    }
                }
            };
//加载省市县
            current = {
                prov: '',
                city: '',
                country: ''
            };
            /*自动加载省份列表*/
            showProv = function () {
                var len = provice.length;
                for (var i = 0; i < len; i++) {
                    var provOpt = document.createElement('option');
                    provOpt.innerText = provice[i]['name'];
                    provOpt.value = i;
                    provOpt.setAttribute('text', provOpt.innerText);
                    $('#prov').append(provOpt);
                }
            };
            /*根据所选的省份来显示城市列表*/
            showCity = function () {
                $('#city').html('<option value="">=请选择城市=</option>');
                var val = $('#prov').val();
                if (val != current.prov) {
                    current.prov = val;
                }
                if (val != null && val !== "") {
                    city.length = 1;
                    var cityLen = provice[val]["city"].length;
                    for (var j = 0; j < cityLen; j++) {
                        var cityOpt = document.createElement('option');
                        cityOpt.innerText = provice[val]["city"][j].name;
                        cityOpt.value = j;
                        cityOpt.setAttribute('text', cityOpt.innerText);
                        $('#city').append(cityOpt);
                    }
                    $('#city').val('0');
                } else {
                    $('#city').val('');
                }
                showCountry();
            };

            /*根据所选的城市来显示县区列表*/
            showCountry = function () {
                $('#country').html('<option value="">=请选择县区=</option>');
                var val = $('#city').val();
                current.city = val;
                if (val != null && val !== "") {
                    country.length = 1;
                    var countryLen = provice[current.prov]["city"][val].districtAndCounty.length;
                    if (countryLen == 0) {
                        return;
                    }
                    for (var n = 0; n < countryLen; n++) {
                        var countryOpt = document.createElement('option');
                        countryOpt.innerText = provice[current.prov]["city"][val].districtAndCounty[n];
                        countryOpt.value = n;
                        countryOpt.setAttribute('text', countryOpt.innerText);
                        $('#country').append(countryOpt);
                    }
                    $('#country').val('0');
                } else {
                    $('#country').val('');
                }
            };

            $("#mallname").blur(function () {
                $("#mallname").val() == '' ? $('.redtip1').css('display', 'inline') : $('.redtip1').css('display', 'none');
            });
            $("#malltel").blur(function () {
                if ($("#malltel").val() == "") {
                    $('.redtip2').css('display', 'none');
                } else {
                    var phone = document.getElementById('malltel').value;
                    phonetset = (/^1[34578]\d{9}$/.test(phone));
                    if (!(/^1[34578]\d{9}$/.test(phone))) {
                        $('.redtip2').css('display', 'inline');
                    } else {
                        $('.redtip2').css('display', 'none');
                    }
                }
            });
            $("#mallact").blur(function () {
                $("#mallact").val() == '' ? $('.redtip3').css('display', 'inline') : $('.redtip3').css('display', 'none');
            });
            $("#mallpwd").blur(function () {
                $("#mallpwd").val() == '' ? $('.redtip4').css('display', 'inline') : $('.redtip4').css('display', 'none');
            });
//edit
            editmall = {
                data: null,
                show: function (obj) {
                    malltype = "edit";
                    editmall.data = obj;
                    $('#modaladd').show();
                    $('#modaladd .title').html('编辑经销商');
                    $("#mallname").val(obj.name);
                    $("#malltel").val(obj.phone);
                    $('.redtip2').css('display', 'none');
                    $(".acctmall").hide();
                    $('.redtip3').css('display', 'none');
                    $('.pwdmall').hide();
                    $('.redtip4').css('display', 'none');
                    showProv();
                    if (obj.province == "") {
                        $('#prov').val("");
                    } else {
                        $('#prov').find('option[text=' + obj.province + ']').attr('selected', true);
                    }
                    showCity();
                    if (obj.city == "") {
                        $('#city').val("");
                    } else {
                        $('#city').find('option[text=' + obj.city + ']').attr('selected', true);
                    }
                    showCountry();
                    if (obj.district == "") {
                        $('#country').val("");
                    } else {
                        $('#country').find('option[text=' + obj.district + ']').attr('selected', true);
                    }
                    $("#malltown").val(obj.town);
                    $("#mallvillage").val(obj.village);
                    $("#mallstreet").val(obj.street);
                    $("#malladdr").val(obj.address);
                    $("#sendaddr").val(obj.send_address);
                    $('#devices').val(obj.device_number_limit);
                }
            };
//delete
            deletemall = {
                data: null,
                showModel: function (str) {
                    deletemall.data = str;
                    $('#modalm').show();
                    $('#contentm').html('确定要删除这条数据？')
                },
                ok: function () {
                    $.get(commonobj.ip + "mall/delete/" + deletemall.data.id).success(function (data) {
                        if (data.code == "0") {
                            $('#modalm').hide();
                            $('#modal').show();
                            $('#content').html("删除成功");
                            getmallmingrid();
                        }
                    }).error(function (data) {
                        $('#modalm').hide();
                        $('#modal').show();
                        $('#content').html(data.responseJSON.msg);
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }


                    });
                },
                cancel: function () {
                    $('#modalm').hide();
                }
            };
//reset
            $("#pwdreset1").blur(function () {
                $("#pwdreset1").val() == '' ? $('.redtip22').css('display', 'inline') : $('.redtip22').css('display', 'none');
            });
            resetpwd1 = {
                resetid1: {},
                show: function (obj) {
                    resetid1 = obj;
                    $('#resetpwd1').show();
                    $('#pwdreset1').val('');
                    $('.redtip22').css('display', 'none');
                },
                ok: function () {
                    if ($('#pwdreset1').val() !== '') {
                        var param = {
                            id: resetid1.id,
                            reset_pwd: $('#pwdreset1').val()
                        };
                        $.ajax({
                            type: "post",
                            url: commonobj.ip + "mall/reset",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify(param),
                            success: function (data) {
                                if (data.msg == "success") {
                                    $('#resetpwd1').hide();
                                    $('#modal').show();
                                    $('#content').html("重置成功");
                                }
                            },
                            error: function (data) {
                                $('#resetpwd1').hide();
                                $('#modal').show();
                                $('#content').html(data.responseJSON.msg);
                                if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                    commonobj.sessionExpired();
                                }


                            }
                        });
                    } else {
                        $('.redtip22').css('display', 'inline');
                    }
                },
                cancel: function () {
                    $('#resetpwd1').hide();
                }
            };
//device
            device = {
                data: null,
                show: function (obj) {
                    device.data = obj;
                    $('#modaldevice').show();
                    if (device.data.devices.length == 0) {
                        $('.devicesTable').hide();
                        $('.modaldevices').show();
                    } else {
                        $('.devicesTable').show();
                        $('.modaldevices').hide();
                        $('.tbodytr').html("");
                        for (var i = 0; i < device.data.devices.length; i++) {
                            $('.tbodytr').append('<tr>' +
                                '<td>' + (i + 1) + '</td>' +
                                '<td>' + device.data.devices[i].name + '</td>' +
                                '<td>' + device.data.devices[i].id + '</td>' +
                                '<td>' + device.data.devices[i].mall_id + '</td>' +
                                '<td>' + device.data.devices[i].model + '</td>' +
                                '<td>' + commonobj.timeservice(device.data.devices[i].bind_timestamp) + '</td>' +
                                '<td>' + device.data.devices[i].device_unique_id + '</td></tr>')
                        }
                    }
                },
                cancel: function () {
                    $('#modaldevice').hide();
                }
            };
//          getphone
            getphone = {
                getphonefun: function (obj) {
                    var user = localStorage.getItem("user");
                    var param = {
                        "account_id": JSON.parse(user).admin_id,
                        "user_id": obj.user_id
                    };
                    $.ajax({
                        type: "post",
                        url: commonobj.ip + "audit/phone",
                        dataType: "json",
                        contentType: "application/json",
                        data: JSON.stringify(param),
                        success: function (data) {
                            if (data.msg == "success") {
                                $('#modalphone').show();
                                $scope.$apply(function () {
                                    $scope.getphonedata = data.data.phone;
                                });
                            }
                        },
                        error: function (data) {
                            $('#modalphone').hide();
                            $('#modal').show();
                            $('#content').html(data.responseJSON.msg);
                            if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                commonobj.sessionExpired();
                            }


                        }
                    });
                },
                cancelfun: function () {
                    $('#modalphone').hide();
                }
            };
            //查询用户体验数据
            getsearchmingrid = function () {
                var grid = $("#maingrid22").ligerGrid({
                    url: commonobj.ip + 'recommend/list',
                    method: "get",
                    parms: [
                        {name: "key", value: $.trim($('#name').val())}
                    ],
                    root: 'list',
                    record: 'total',
                    pageParmName: 'start',
                    pagesizeParmName: 'limit',
                    width: '98%',
                    height: '98%',
                    pageSize: 10,
                    pageSizeOptions: [10, 20, 30, 50],
                    rownumbers: true,
                    columns: [
                        {display: '门店名称', name: 'mall_name', align: 'left', width: "10%"},
                        {display: '用户名称', name: 'user_name', align: 'left', width: "10%"},
                        {
                            display: '电话', name: 'phone',
                            render: function (rowdata, rowindex, value) {
                                var str = JSON.stringify(rowdata);
                                var html = '';
                                html +=
                                    "<a class='text-primary operate_text' onclick='getphone.getphonefun(" + str + ")'>获取电话</a>&nbsp;&nbsp;";
                                return html;
                            }
                        },
                        {display: '年龄', name: 'age_value', align: 'left'},
                        {
                            display: '性别', name: 'gender_value', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == 0) {
                                    return "男";
                                } else if (value == 1) {
                                    return "女";
                                }
                            }
                        },
                        {display: '身高(cm)', name: 'height_value', align: 'left'},
                        {display: '体重(kg)', name: 'weight_value', align: 'left'},
                        {
                            display: 'bmi指数', name: 'bmi_value', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                return parseInt(value, 10);
                            }
                        },
                        {
                            display: '怀孕状态', name: 'pregnant_value', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == 0) {
                                    return "备孕";
                                } else if (value == 1) {
                                    return "备孕";
                                } else if (value == 2) {
                                    return "产后2年内";
                                } else if (value == 3) {
                                    return "无";
                                }
                            }
                        },
                        {display: 'psqi得分', name: 'psqi_value', align: 'left'},
                        {
                            display: '推荐产品型号', name: 'recommended_mattress_production', align: 'left', width: '15%',
                            render: function (rowdata, rowindex, value) {
                                var str = "";
                                for (var i = 0; i < value.length; i++) {
                                    if (i == 0) {
                                        str += value[i].name;
                                    } else {
                                        str += ',' + value[i].name;
                                    }
                                }
                                return str;
                            }
                        },
                        {
                            display: '体验时间', name: 'timestamp', align: 'left', width: "10%",
                            render: function (rowdata, rowindex, value) {
                                return commonobj.timeservice(value);
                            }
                        },
                        {
                            display: '操作',
                            render: function (rowdata, rowindex, value) {
                                var str = JSON.stringify(rowdata);
                                var html = '';
                                html +=
                                    "<a class='text-primary operate_text' onclick='malltab2.detailsmodal( " + str + ")'>详情</a>&nbsp;&nbsp;";
                                return html;
                            }
                        }
                    ]
                });
                grid.bind('Success', function (data) {
                    if (data.list.length == 0) {
                        $("#zwsj22").show();
                    } else {
                        $("#zwsj22").hide();
                    }
                });
                grid.bind('Error', function (data) {
                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                        commonobj.sessionExpired();
                    }

                });

                //查询时改变页码数
                grid.changePage("first");
                grid.loadData();
            };
            updategrid = function () {
                getsearchmingrid();
            };
            // 查询雇员信息
            getemployeemingrid = function () {
                var grid = $("#maingrid23").ligerGrid({
                    url: commonobj.ip + 'wx/mall_employer/query',
                    method: "get",
                    parms: [],
                    root: 'data',
                    record: 'total',
                    pageParmName: 'start',
                    pagesizeParmName: 'limit',
                    width: '98%',
                    height: '98%',
                    pageSize: 10,
                    pageSizeOptions: [10, 20, 30, 50],
                    rownumbers: true,
                    columns: [
                        {
                            display: '用户名称', name: 'nick', width: "12%",
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {display: '门店ID', name: 'mall_id', width: "15%"},
                        {
                            display: '性别', name: 'gender', width: "10%",
                            render: function (rowdata, rowindex, value) {
                                if (value == "male") {
                                    return "男";
                                } else if (value == "female") {
                                    return "女";
                                } else if (value == null) {
                                    return "--";
                                }
                            }
                        },
                        {
                            display: '电话', name: 'phone', width: "12%",
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {
                            display: '国家', name: 'country', width: "12%",
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {
                            display: '省', name: 'province', width: "12%",
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {
                            display: '市', name: 'city', width: "12%",
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {
                            display: '状态', name: 'status', width: "15%",
                            render: function (rowdata, rowindex, value) {
                                if (value == "NORMAL") {
                                    return "正常";
                                } else if (value == "VACATION") {
                                    return "休假";
                                } else if (value == "QUIT") {
                                    return "辞职";
                                } else if (value == null) {
                                    return "--";
                                }

                            }
                        }

                    ]


                });
                grid.bind('Success', function (data) {
                    if (data.data.length == 0) {
                        $("#zwsj23").show();
                    } else {
                        $("#zwsj23").hide();
                    }
                });
                grid.bind('Error', function (data) {
                    if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                        commonobj.sessionExpired();
                    }

                });

                //查询时改变页码数
                grid.changePage("first");
                grid.loadData();
            };
            //查询订单信息
            getordermingrid = function () {
                var paramSearch = {};
                start_time_data = $("#start_time").val();
                end_time_data = $("#end_time").val();
                var user_name = $.trim($('#user_name').val());
                var mall_employer_name = $.trim($('#employer_name').val());
                var mall_name = $.trim($('#mall_name').val());
                if (start_time_data != "") {
                    paramSearch.st = new Date(start_time_data).getTime();
                }
                if (end_time_data != "") {
                    paramSearch.et = new Date(end_time_data).getTime();
                }
                if (user_name != "") {
                    paramSearch.user_name = user_name;
                }
                if (mall_employer_name != "") {
                    paramSearch.mall_employer_name = mall_employer_name;
                }
                if (mall_name != "") {
                    paramSearch.mall_name = mall_name;
                }
                var grid = $("#maingrid24").ligerGrid({
                    url: commonobj.ip + 'order/query',
                    method: "get",
                    urlParms: paramSearch,
                    root: 'data',
                    //record: 'total',
                    pageParmName: 'start',
                    pagesizeParmName: 'limit',
                    width: '100%',
                    height: '98%',
                    pageSize: 10,
                    pageSizeOptions: [10, 20, 30, 50],
                    rownumbers: false,
                    columns: [
                        {display: '订单ID', name: 'id', align: 'left', width: "10%"},
                        {
                            display: '订单类型', name: 'is_custom', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value) {
                                    return "定制订单";
                                } else {
                                    return "产品订单";
                                }
                            }
                        },
                        {display: '门店名称', name: 'mall_name', align: 'left'},
                        {display: '用户名称', name: 'user_name', align: 'left'},
                        {
                            display: '订单下单雇员名', name: 'mall_employer_name', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {display: 'recommend_report_id', name: 'recommend_report_id', align: 'left'},
                        {
                            display: '邮寄地址', name: 'deliver_address', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == null) {
                                    return "--";
                                } else {
                                    return value;
                                }
                            }
                        },
                        {
                            display: '下单时间', name: 'create_timestamp', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == 0 || value == null) {
                                    return "--";
                                } else {
                                    return commonobj.timeservice(value);
                                }
                            }
                        },
                        {
                            display: '状态更新时间', name: 'update_timestamp', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == 0 || value == null) {
                                    return "--";
                                } else {
                                    return commonobj.timeservice(value);
                                }
                            }
                        },
                        {
                            display: '状态', name: 'status', align: 'left',
                            render: function (rowdata, rowindex, value) {
                                if (value == "UNCONFIRMED") {
                                    return "未确认";
                                } else if (value == "ORDERED") {
                                    return "已下单";
                                } else if (value == "PRODUCING") {
                                    return "生产中";
                                } else if (value == "TRANSPORTING") {
                                    return "运输中";
                                } else if (value == "DISPATCHING") {
                                    return "配送中";
                                } else if (value == "DONE") {
                                    return "完成";
                                } else if (value == "CANCELED") {
                                    return "取消";
                                } else if (value === "VERIFY_FAILED") {
                                    return "鉴伪失败";
                                } else {
                                    return value;
                                }

                            }
                        },
                        {
                            display: '操作',
                            render: function (rowdata, rowindex, value) {
                                var str = JSON.stringify(rowdata);
                                var html = '';
                                html +=
                                    "<a class='text-primary operate_text' onclick='editOrder.show(" + str + ")'>编辑</a>&nbsp;&nbsp;" +
                                    "<a class='text-primary operate_text' onclick='exportadmin.export( " + str + ")'>导出</a>";
                                return html;
                            }
                        }
                    ],
                    detail: {onShowDetail: f_showOrder}
                });
                grid.bind('Success', function (data) {
                    $scope.orderData = [];
                    if (data.data == null || data.data.length == 0) {
                        $("#zwsj24").show();
                    } else {
                        $scope.orderData = data.data;
                        for (var i = 0; i < $scope.orderData.length; i++) {
                            if (!$scope.orderData[i].is_custom) {
                                for (var j = 0; j < $scope.orderData[i].production_list.length; j++) {
                                    $scope.orderData[i].production_list[j].product_name = getproductionname($scope.orderData[i].production_list[j].product_code);
                                }
                            }

                        }
                        $("#zwsj24").hide();
                    }
                });
                //查询时改变页码数
                grid.changePage("first");
                grid.loadData();
            };
            $scope.showStatusOption = false;
            editOrder = {
                data: null,
                show: function (obj) {
                    showorderstatus();
                    $scope.showStatusOption = true;
                    obj.create_timestamp = obj.create_timestamp ? commonobj.timeservice(obj.create_timestamp) : "--";
                    obj.update_timestamp = obj.update_timestamp ? commonobj.timeservice(obj.update_timestamp) : "--";
                    $scope.$apply(function () {
                        $scope.editdata = obj;
                    });
                    type = "edit";
                    var statusTemp = "=请选择状态=";
                    orderstatusdata.forEach(function (item, index) {
                        if (item.name === obj.status) {
                            statusTemp = index;
                        }
                    });
                    $('#editmodaldetails').show();
                    $('#editmodaldetails .title').html('编辑订单状态');
                    $('#orderstatus').val(statusTemp);
                },
                okfun: function () {
                    if ($('#orderstatus').val() !== "") {
                        var statusval = orderstatusdata[$('#orderstatus').val()].name;
                        var param = {
                            "id": $scope.editdata.id,
                            "status": statusval
                        };
                        $.ajax({
                            type: "put",
                            url: commonobj.ip + "order/update/order/status",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify(param),
                            success: function (data) {
                                if (data.msg == "success") {
                                    $('#editmodaldetails').hide();
                                    $('#editmodalcontent').html("");
                                    $('#editmodalresult').show();
                                    $('#editmodalcontent').html("编辑成功");
                                    getordermingrid();
                                }
                            },
                            error: function (data) {
                                $('#editmodaldetails').hide();
                                $('#editmodalcontent').html("");
                                $('#editmodalresult').show();
                                $('#editmodalcontent').html(data.responseJSON.msg);
                                if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                    commonobj.sessionExpired();
                                }


                            }
                        });
                    } else {
                        $('#editmodalcontent').html("");
                        $('#editmodalresult').show();
                        $('#editmodalcontent').html("请选择状态");
                    }
                },
                cancelfun: function () {
                    $('#editmodaldetails').hide();
                },
                closebackmsg: function () {
                    $('#editmodalresult').hide();
                }
            };
            exportadmin = {
                export: function (data) {
                    window.open(commonobj.ip + "order/export/" + data.id);
                }
            };
            showorderstatus = function () {
                if ($scope.showStatusOption) {
                    return;
                }
                var len = orderstatusdata.length;
                for (var i = 0; i < len; i++) {
                    var provOpt = document.createElement('option');
                    provOpt.innerText = orderstatusdata[i]['display'];
                    provOpt.value = i;
                    provOpt.setAttribute('text', provOpt.innerText);
                    $('#orderstatus').append(provOpt);
                }
            };

            function f_getOrdersData(CustomerID) {
                var AllOrdersData = $scope.orderData;
                var data = {Rows: []};
                for (var i = 0; i < AllOrdersData.length; i++) {
                    if (AllOrdersData[i].id == CustomerID) {
                        data.Rows = AllOrdersData[i].is_custom ? AllOrdersData[i].custom_list : AllOrdersData[i].production_list;
                        break;
                    }
                }
                return data;
            }

            function f_showOrder(row, detailPanel, callback) {
                var grid = document.createElement('div');
                $(detailPanel).append(grid);
                if (!row.is_custom) {
                    $(grid).css('margin', 40).ligerGrid({
                        columns:
                            [
                                {
                                    display: '产品名称', name: 'product_code', type: 'float', width: '20%', minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        return getproductionname(value);
                                    }
                                },
                                {display: '订单ID', name: 'order_id', type: 'float', width: '20%', minWidth: 200},
                                {
                                    display: '产品创建时间',
                                    name: 'create_timestamp',
                                    type: 'float',
                                    width: '20%',
                                    minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        if (value == 0 || value == null) {
                                            return "--";
                                        } else {
                                            return commonobj.timeservice(value);
                                        }
                                    }
                                },
                                {
                                    display: '产品更新时间', name: 'update_timestamp', width: '20%', minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        if (value == 0 || value == null) {
                                            return "--";
                                        } else {
                                            return commonobj.timeservice(value);
                                        }
                                    }
                                },
                                {
                                    display: '产品状态', name: 'status', width: '20%', minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        if (value == "NOT_VERIFIED") {
                                            return "未鉴伪";
                                        } else if (value == "PASSED") {
                                            return "鉴伪通过";
                                        } else if (value == "VERIFICATION_TOKEN_ABSENT") {
                                            return "鉴伪码不存在";
                                        } else if (value == "VERIFICATION_PRODUCT_MISMATCH") {
                                            return "鉴伪码型号不匹配";
                                        } else if (value == "VERIFICATION_TOKEN_ALREADY_USED") {
                                            return "鉴伪码失效";
                                        }

                                    }
                                }
                            ],
                        isScroll: false,
                        showToggleColBtn: false,
                        width: '90%',
                        height: '98%',
                        data: f_getOrdersData(row.id),
                        showTitle: false,
                        onAfterShowData: callback,
                        frozen: false
                    });
                } else {
                    $(grid).css('margin', 40).ligerGrid({
                        columns:
                            [
                                {
                                    display: 'NO',
                                    name: 'idx',
                                    width: '5%',
                                    minWidth: 50,
                                    height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == null) {
                                            tempValue = "--";
                                        } else {
                                            tempValue = value + 1;
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '尺寸', name: 'chicun', width: '5%', minWidth: 80, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html = "<div style='line-height:120px;'>180*200</div>";
                                        return html;

                                    }
                                },
                                {
                                    display: '订单ID', name: 'order_id', width: '10%', minWidth: 200, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + value +
                                            "</div>";
                                        return html;

                                    }
                                },
                                {
                                    display: '创建时间',
                                    name: 'create_timestamp',
                                    width: '10%',
                                    minWidth: 150,
                                    height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == 0 || value == null) {
                                            tempValue = "--";
                                        } else {
                                            tempValue = commonobj.timeservice(value);
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '更新时间', name: 'update_timestamp', width: '10%', minWidth: 150, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == 0 || value == null) {
                                            tempValue = "--";
                                        } else {
                                            tempValue = commonobj.timeservice(value);
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '定制规格', columns: [{
                                        display: '定制层', name: 'order_id', width: 100, height: 40,
                                        render: function (rowdata, rowindex, value) {
                                            var str = JSON.stringify(rowdata);
                                            var html = '';
                                            html +=
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "弹簧层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "柔软层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "亲肤层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "面料层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "工艺" +
                                                "</div>" +
                                                "<div style='height:20px;text-align: center;'>" + "硬质层" +
                                                "</div>";
                                            return html;
                                        }
                                    }, {
                                        display: '编码', name: 'order_id', width: 100, height: 40,
                                        render: function (rowdata, rowindex, value) {
                                            var html = '';
                                            var support_code = rowdata.support_code || "--";
                                            var soft_code = rowdata.soft_code || "--";
                                            var skin_code = rowdata.skin_code || "--";
                                            var surface_code = rowdata.surface_code || "--";
                                            var craft_code = rowdata.craft_code || "--";
                                            var hard_code = rowdata.hard_code || "--";
                                            html +=
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + support_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + soft_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + skin_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + surface_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + craft_code +
                                                "</div>" +
                                                "<div style='height:20px;text-align: center;'>" + hard_code +
                                                "</div>";
                                            return html;
                                        }
                                    }, {
                                        display: '名称', name: 'order_id', width: 200, height: 40,
                                        render: function (rowdata, rowindex, value) {
                                            var str = JSON.stringify(rowdata);
                                            var html = '';
                                            var support_name = rowdata.support_detail ? rowdata.support_detail.name : "--";
                                            var soft_name = rowdata.soft_detail ? rowdata.soft_detail.name : "--";
                                            var skin_name = rowdata.skin_detail ? rowdata.skin_detail.name : "--";
                                            var surface_name = rowdata.surface_detail ? rowdata.surface_detail.name : "--";
                                            var craft_name = rowdata.craft_detail ? rowdata.craft_detail.name : "--";
                                            var hard_name = rowdata.hard_detail ? rowdata.hard_detail.name : "--";
                                            html +=
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + support_name + "'>" + support_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + soft_name + "' >" + soft_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + skin_name + "'>" + skin_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + surface_name + "'>" + surface_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + craft_name + "'>" + craft_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;text-align: center;' title='" + hard_name + "'>" + hard_name +
                                                "</div>";
                                            return html;
                                        }
                                    }]
                                },
                                {
                                    display: '折扣率', name: 'rate', width: '10%', minWidth: 50, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html = "<div style='line-height:120px;'>100%</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '金额',
                                    name: 'total_price',
                                    type: 'float',
                                    width: '10%',
                                    minWidth: 100,
                                    height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + value +
                                            "</div>";
                                        return html;

                                    }
                                },
                                {
                                    display: '产品状态', name: 'status', width: '10%', minWidth: 100, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == "NOT_VERIFIED") {
                                            tempValue = "未鉴伪";
                                        } else if (value == "PASSED") {
                                            tempValue = "鉴伪通过";
                                        } else if (value == "VERIFICATION_TOKEN_ABSENT") {
                                            tempValue = "鉴伪码不存在";
                                        } else if (value == "VERIFICATION_PRODUCT_MISMATCH") {
                                            tempValue = "鉴伪码型号不匹配";
                                        } else if (value == "VERIFICATION_TOKEN_ALREADY_USED") {
                                            tempValue = "鉴伪码失效";
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                }
                            ],
                        isScroll: false,
                        showToggleColBtn: false,
                        width: '90%',
                        rowHeight: 120,
                        data: f_getOrdersData(row.id),
                        showTitle: false,
                        onAfterShowData: callback,
                        frozen: false
                    });
                }
            }

            function getproductionname(value) {
                var productname = "--";
                for (var i = 0; i < $scope.productdata.length; i++) {
                    if (value === $scope.productdata[i].code) {
                        productname = $scope.productdata[i].name;
                    }
                }
                return productname;
            }

            showtab = function (type) {
                $('.site-menu-item').removeClass('menusel');
                if (type == "admin") {
                    $('.admin').show();
                    $(".mall").hide();
                    $('.searchmenu').hide();
                    $('#adminmenu').addClass('menusel');
                    $(".employee").hide();
                    $(".order").hide();
                    getadmingrid();
                } else if (type == "mall") {
                    $('.admin').hide();
                    $(".mall").show();
                    $('.searchmenu').hide();
                    $('#mallmenu').addClass('menusel');
                    $('.list').show();
                    $('.details').hide();
                    $(".employee").hide();
                    $(".order").hide();
                    getmallmingrid();
                } else if (type == "searchmenu") {
                    $('.admin').hide();
                    $(".mall").hide();
                    $('#searchmenu').addClass('menusel');
                    $('.searchmenu').show();
                    $(".employee").hide();
                    $(".order").hide();
                    getsearchmingrid();
                } else if (type == "employee") {
                    $('.admin').hide();
                    $(".mall").hide();
                    $('#employeemenu').addClass('menusel');
                    $('.searchmenu').hide();
                    $(".employee").show();
                    $(".order").hide();
                    getemployeemingrid();
                } else if (type == "order") {
                    $('.admin').hide();
                    $(".mall").hide();
                    $('#ordermenu').addClass('menusel');
                    $('.searchmenu').hide();
                    $(".employee").hide();
                    $(".order").show();
                    start_time = $("#start_time").ligerDateEditor(
                        {

                            format: "yyyy-MM-dd hh:mm:ss",
                            label: '开始时间',
                            labelWidth: 80,
                            //width:140,
                            labelAlign: 'center',
                            cancelable: true,
                            showTime: true
                        });
                    end_time = $("#end_time").ligerDateEditor(
                        {

                            format: "yyyy-MM-dd hh:mm:ss",
                            label: '结束时间',
                            labelWidth: 80,
                            //width:140,
                            labelAlign: 'center',
                            cancelable: true,
                            showTime: true
                        });
                    getordermingrid();
                }
            };
//malltab2
            malltab2 = {
                data: null,
                show: function (obj) {
                    malltab2.data = obj;
                    $scope.$apply(function () {
                        $scope.malltab2data = obj;
                    });
                    $('.list').hide();
                    $('.details').show();
                    malltab2.tabclick('home');
                    malltab2.device();
                },
                tabclick: function (name) {
                    $('#myTab li').removeClass('active');
                    $('#myTab li.' + name).addClass('active');
                    $('#myTabContent .tab-pane').removeClass('active');
                    $('#myTabContent .tab-pane').removeClass('in');
                    $('#' + name).addClass('active');
                    $('#' + name).addClass('in');
                    if (name == "ios") {
                        malltab2.recommend();
                    }
                },
                device: function () {
                    if (malltab2.data.devices.length == 0) {
                        $('.devicesTable').hide();
                        $('.modaldevices').show();
                    } else {
                        $('.devicesTable').show();
                        $('.modaldevices').hide();
                        $('.tbodytr').html("");
                        for (var i = 0; i < malltab2.data.devices.length; i++) {
                            $('.tbodytr').append('<tr>' +
                                '<td>' + (i + 1) + '</td>' +
                                '<td>' + malltab2.data.devices[i].name + '</td>' +
                                '<td>' + malltab2.data.devices[i].id + '</td>' +
                                '<td>' + malltab2.data.devices[i].mall_id + '</td>' +
                                '<td>' + malltab2.data.devices[i].model + '</td>' +
                                '<td>' + commonobj.timeservice(malltab2.data.devices[i].bind_timestamp) + '</td>' +
                                '<td>' + malltab2.data.devices[i].device_unique_id + '</td></tr>')
                        }
                    }
                },
                recommend: function () {
                    var grid = $("#maingrid2").ligerGrid({
                        url: commonobj.ip + 'recommend/list',
                        method: "get",
                        parms: [
                            {name: 'mall_id', value: malltab2.data.id}
                        ],
                        root: 'list',
                        record: 'total',
                        pageParmName: 'start',
                        pagesizeParmName: 'limit',
                        width: '98%',
                        height: '98%',
                        pageSize: 10,
                        pageSizeOptions: [10, 20, 30, 50],
                        rownumbers: true,
                        columns: [
                            {display: '用户名称', name: 'user_name', align: 'left', width: "10%"},
                            {
                                display: '电话', name: 'phone',
                                render: function (rowdata, rowindex, value) {
                                    var str = JSON.stringify(rowdata);
                                    var html = '';
                                    html +=
                                        "<a class='text-primary operate_text' onclick='getphone.getphonefun(" + str + ")'>获取电话</a>&nbsp;&nbsp;";
                                    return html;
                                }
                            },
                            {display: '年龄', name: 'age_value', align: 'left'},
                            {
                                display: '性别', name: 'gender_value', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == 0) {
                                        return "男";
                                    } else if (value == 1) {
                                        return "女";
                                    }
                                }
                            },
                            {display: '身高(cm)', name: 'height_value', align: 'left'},
                            {display: '体重(kg)', name: 'weight_value', align: 'left'},
                            {
                                display: 'bmi指数', name: 'bmi_value', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    return parseInt(value, 10);
                                }
                            },
                            {
                                display: '怀孕状态', name: 'pregnant_value', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == 0) {
                                        return "备孕";
                                    } else if (value == 1) {
                                        return "备孕";
                                    } else if (value == 2) {
                                        return "产后2年内";
                                    } else if (value == 3) {
                                        return "无";
                                    }
                                }
                            },
                            {display: 'psqi得分', name: 'psqi_value', align: 'left'},
                            {
                                display: '推荐产品型号', name: 'recommended_mattress_production', align: 'left', width: "15%",
                                render: function (rowdata, rowindex, value) {
                                    var str = "";
                                    for (var i = 0; i < value.length; i++) {
                                        if (i == 0) {
                                            str += value[i].name;
                                        } else {
                                            str += ',' + value[i].name;
                                        }
                                    }
                                    return str;
                                }
                            },
                            {
                                display: '体验时间', name: 'timestamp', align: 'left', width: "10%",
                                render: function (rowdata, rowindex, value) {
                                    return commonobj.timeservice(value);
                                }
                            },
                            {
                                display: '操作',
                                render: function (rowdata, rowindex, value) {
                                    var str = JSON.stringify(rowdata);
                                    var html = '';
                                    html +=
                                        "<a class='text-primary operate_text' onclick='malltab2.detailsmodal( " + str + ")'>详情</a>";
                                    return html;
                                }
                            }
                        ]
                    });
                    grid.bind('Success', function (data) {
                        if (data.list == null || data.list.length == 0) {
                            $("#zwsj2").show();
                        } else {
                            $("#zwsj2").hide();
                        }
                    });
                    grid.bind('Error', function (data) {
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }

                    });

                },
                detailsmodal: function (obj) {
                    $('#modaldetails').show();
                    $scope.$apply(function () {
                        $scope.deviceObj = angular.copy(obj);
                    });
                },
                canceldetailmodal: function () {
                    $('#modaldetails').hide();
                },
                backhtml: function () {
                    $('.list').show();
                    $('.details').hide();
                }
            };
            searchOrderInfor = function () {
                getordermingrid();
            };
            logout = function () {
                localStorage.setItem("user", "");
                window.document.location.href = commonobj.getRootPath() + '/views/login.html';
            };
            init = function () {
                $('#right').width($(document).width() - 185 - 20);
                var user = localStorage.getItem("user");
                if (user == null || user == "") {
                    window.document.location.href = commonobj.getRootPath() + '/views/login.html';
                }
                showtab('admin');
                getproductdata();
            };
            init();

            function getproductdata() {
                $.ajax({
                    type: "GET",
                    url: commonobj.ip + "/product/query",
                    dataType: "json",
                    contentType: "application/json",
                    success: function (data) {
                        if (data.msg == "success") {
                            $scope.productdata = data.data;
                        } else {
                            $scope.productdata = [];
                        }
                    },
                    error: function (data) {
                        $scope.productdata = [];
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }


                    }
                });
            };
            unloadhtml = function () {
                //localStorage.setItem("user", "");
            };
        }
    ]);
$(document).ready(function () {
    $('#right').width($(document).width() - 185 - 20);
});
